package com.jl.sms;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.GregorianCalendar;

import com.jl.util.HexUtil;

public class TPServiceCentreTimeStamp implements TransferLayerProtocol{

	/**yyyyMMddHHmmssZZ*/
	private String timestamp;

	public TPServiceCentreTimeStamp(){
	}
	
	public TPServiceCentreTimeStamp(byte[] timestamp){
		this.timestamp = HexUtil.toHexCompact(timestamp);
	}
	/**
	 * 
	 * @param timestamp the format is "yyyyMMddHHmmssZZ"
	 */
	public TPServiceCentreTimeStamp(String timestamp){
		this.timestamp = timestamp;
	}
	
	@Override
	public byte[] value() {
		return HexUtil.parseHexToByteArray(timestamp);
	}

	@Override
	public String valueAsString() {
		if(timestamp == null){
			Calendar calendar = new GregorianCalendar();
			SimpleDateFormat format = new SimpleDateFormat("yyyyMMddHHmmss");
			String time = format.format(calendar.getTime());
			return time + "08";
		}else{
			return timestamp;
		}
	}

}
